<?php

namespace app\admin\model\order;

use app\admin\model\Admin;
use app\admin\model\goods\Brand;
use app\admin\model\goods\Goods;
use think\Model;


class OrderGoodsStatusRecord extends Model
{
    // 表名
    protected $name = 'order_goods_status_record';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    protected $append = ['before_change_text', 'after_change_text', 'create_time_text'];


    /**
     * 获取订单的出货状态
     */
    public function getBeforeChangeTextAttr($value, $data) {
        $status = [
            -1 => '取消订单',
            0 => '准备下单',
            1 => '已下单',
            2 => '现货',
            3 => '付款预定',
            4 => '口头预定',
            5 => '入库',
            6 => '韩国已发货',
            7 => '待定',
            '8-1' => '退款 - 延迟',
            '8-2' => '退款 - 断货',
            '8-3' => '退款 - 特殊',
            '9-1' => '换货 - 颜色',
            '9-2' => '换货 - 尺码',
            '9-3' => '换货 - 瑕疵',
            '9-4' => '换货 - 款式',
            10 => '已提货',
        ];
        return $status[$data['before_change']];
    }

    public function getAfterChangeTextAttr($value, $data) {
        $status = [
            -1 => '取消订单',
            0 => '准备下单',
            1 => '已下单',
            2 => '现货',
            3 => '付款预定',
            4 => '口头预定',
            5 => '入库',
            6 => '韩国已发货',
            7 => '待定',
            '8-1' => '退款 - 延迟',
            '8-2' => '退款 - 断货',
            '8-3' => '退款 - 特殊',
            '9-1' => '换货 - 颜色',
            '9-2' => '换货 - 尺码',
            '9-3' => '换货 - 瑕疵',
            '9-4' => '换货 - 款式',
            10 => '已提货',
        ];
        return $status[$data['after_change']];
    }

    public function getCreateTimeTextAttr($value, $data){
        return date('m-d/H:i', $data['create_time']);
    }

    public function admin(){
        return $this->hasOne(Admin::class, 'id', 'admin_id');
    }

}